//
//  OALoginCell.m
//  LongOA
//
//  Created by 耿用强 on 15/7/4.
//  Copyright (c) 2015年 耿用强. All rights reserved.
//

#import "OALoginCell.h"

@implementation OALoginCell
{
    UIImageView*_blackView;
    UILabel*_nameLabel;
    NSIndexPath*_index;
    
    
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor=[UIColor clearColor];
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        
        _blackView=[[UIImageView alloc]init];
        //        _blackView.layer.masksToBounds=YES;
        _blackView.layer.borderColor=[[UIColor lightGrayColor]CGColor];
        _blackView.layer.borderWidth=1;
        _blackView.userInteractionEnabled=YES;
        [self addSubview:_blackView];
        
        
        _nameLabel=[[UILabel alloc]init];
        _nameLabel.textColor=[UIColor blackColor];
        _nameLabel.font=FONT_15;
        [_blackView addSubview:_nameLabel];
        
        
        _textField=[[UITextField alloc]init];
        _textField.delegate=self;
         [_textField addTarget:self action:@selector(textwithText:) forControlEvents:UIControlEventEditingChanged];
        _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _textField.backgroundColor=[UIColor clearColor];
        _textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        _textField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
        _textField.font=FONT_BOLD_14;
        _textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
        _textField.textColor=[UIColor darkGrayColor];
        [_blackView addSubview:_textField];
    }
    return self;
}

- (void)showName:(NSString*)text andPloadText:(NSString*)ploadText andIndex:(NSIndexPath *)index
{
    _index=index;
    _nameLabel.text=text;
    _textField.placeholder=ploadText;
    
    //2015.09.13
    if ([ploadText isEqualToString:@"请输入IP地址"]) {
        _textField.text=@"223.4.178.191";
        
        if ([_delegate respondsToSelector:@selector(loginCellTextFieldWithText:andIndex:)]) {
            [_delegate loginCellTextFieldWithText:_textField.text andIndex:_index];
        }
    } else if ([ploadText isEqualToString:@"请输入端口号"]) {
        _textField.text=@"30031";
        if ([_delegate respondsToSelector:@selector(loginCellTextFieldWithText:andIndex:)]) {
            [_delegate loginCellTextFieldWithText:_textField.text andIndex:_index];
        }
    }
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    _blackView.frame=CGRectMake(RESIZE_UI(15), 0, self.width-RESIZE_UI(30), self.height);
    _nameLabel.frame=CGRectMake(RESIZE_UI(10), 0, RESIZE_UI(84), _blackView.height);
    _textField.frame=CGRectMake(_nameLabel.right+RESIZE_UI(5), 0, _blackView.width-RESIZE_UI(10)-_nameLabel.right, _blackView.height);
}




- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)textwithText:(UITextField*)textField
{
    if ([_delegate respondsToSelector:@selector(loginCellTextFieldWithText:andIndex:)]) {
        [_delegate loginCellTextFieldWithText:textField.text andIndex:_index];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
